<%-- 
    Document   : relatorioProducaoGrupoGerencial
    Created on : 15/11/2010, 17:51:18
    Author     : Thiago
--%>

<%@page import="dao.TipoGrupoInspecaoDAO"%>
<%@page import="crypt.Crypt"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="bo.*"%>
<%@page import="beans.*"%>
<%@page import="autenticacao.Sessao"%>
<%

            String moduleId = "33";
            Crypt crypt = new Crypt();
            try {
                crypt.setKey(crypt.Decifragem((String) session.getAttribute("userPhrase")));
                String desafio = crypt.Cifragem(moduleId + "@" + ferramentas.DataHora.formatarDataHora(ferramentas.DataHora.retornarDataHoraAtual(), ferramentas.DataHora.DATE_TIME_FORMAT));
                if (!(new Sessao(session).validarSessao(desafio))) {
                    response.sendRedirect("/" + request.getContextPath());
                }
            } catch (Exception e) {
                response.sendRedirect("/" + request.getContextPath());
            }

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Gestor Operacional</title>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/style.css" type="text/css" rel="stylesheet"/>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/table.css" type="text/css" rel="stylesheet"/>
        <link href="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>css/anytime.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/jquery.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/anytime.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/anytimetz.js"></script>
        <script type="text/javascript" src="<%out.print(new String(request.getRequestURL()).split("pages")[0]);%>scripts/table.js"></script>
    </head>
    <body>
        <table width="100%">
            <tr>
                <td>
                    <jsp:include page = "../menu.jsp" flush = "true"/>
                </td>
            </tr>

            <tr align="center">
                <td><br/><br/>
                    <form name="form1" action="relatorioProducaoGrupoGerencial.jsp" method="post">
                        <input type="hidden" name="exibirRelatorio" value="true">
                        <table border="1" cellspacing="0" width="450" bgcolor="#FFFFFF">
                            <tr>
                                <td width="110">Monitor:</td>
                                <td align="center">
                                    <select name="monitor" size="1">
                                        <option value="" selected>Todos</option>
                                        <%
                                                    ArrayList<Colaborador> alc = null;
                                                    try {
                                                        alc = new ColaboradorBO().recuperarColaborador(null);
                                                    } catch (Exception e) {
                                                        out.println(e.getMessage());
                                                    }
                                                    if (alc != null) {
                                                        for (int i = 0; i < alc.size(); i++) {
                                                            out.println("<option value=\"" + alc.get(i).getMatricula() + "\">" + alc.get(i).getMatricula() + " - " + alc.get(i).getNome() + "</option>");
                                                        }
                                                    }

                                        %>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>Monitorado:</td>
                                <td align="center">
                                    <select name="monitorado" size="1">
                                        <option value="" selected>Todos</option>
                                        <%
                                                    if (alc != null) {
                                                        for (int i = 0; i < alc.size(); i++) {
                                                            out.println("<option value=\"" + alc.get(i).getMatricula() + "\">" + alc.get(i).getMatricula() + " - " + alc.get(i).getNome() + "</option>");
                                                        }
                                                    }

                                        %>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>Grupo:</td>
                                <td align="center">
                                    <select name="grupo" size="1">
                                        <option value="" selected>Todos</option>
                                        <%
                                                    ArrayList<TipoGrupoInspecao> altg = null;
                                                    try {
                                                        altg = new TipoGrupoInspecaoDAO().recuperarTipoGrupoInspecao(null);
                                                    } catch (Exception e) {
                                                        out.println(e.getMessage());
                                                    }
                                                    if (altg != null) {
                                                        for (int i = 0; i < altg.size(); i++) {
                                                            out.println("<option value=\"" + altg.get(i).getId() + "\">" + altg.get(i).getDescricao() + "</option>");
                                                        }
                                                    }

                                        %>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>Processo:</td>
                                <td align="center">
                                    <select name="processo" size ="1">
                                        <option value="" selected>Todos</option>
                                        <%
                                                    ArrayList<Processo> alp = null;
                                                    try {
                                                        alp = new ProcessoBO().recuperarProcessos(null);
                                                    } catch (Exception e) {
                                                        out.println(e.getMessage());
                                                    }
                                                    if (alp != null) {
                                                        for (int i = 0; i < alp.size(); i++) {
                                                            out.println("<option value=\"" + alp.get(i).getId() + "\">" + alp.get(i).getDescricao() + "</option>");
                                                        }
                                                    }

                                        %>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>Data Expediente Inicio:</td>
                                <td align="center">
                                    <input id="data" name="data" type="text" maxlength="10" size="10">
                                    <script type="text/javascript">
                                        AnyTime.picker( "data",
                                        { format: "%d/%m/%z", firstDOW: 0 } );
                                    </script>
                                </td>
                            </tr>
                            <tr>
                                <td>Data Expediente Fim:</td>
                                <td align="center">
                                    <input id="dataFim" name="dataFim" type="text" maxlength="10" size="10">
                                    <script type="text/javascript">
                                        AnyTime.picker( "dataFim",
                                        { format: "%d/%m/%z", firstDOW: 0 } );
                                    </script>
                                </td>
                            </tr>
                            <tr><td>Site:</td>
                                <td align="center">
                                    <select name="site" size="1">
                                        <option value="" selected>Todos</option>
                                        <%
                                                    ArrayList<Site> als = null;
                                                    try {
                                                        als = new SiteBO().recuperarSite(null);
                                                    } catch (Exception e) {
                                                        out.println(e.getMessage());
                                                    }
                                                    if (als != null) {
                                                        for (int i = 0; i < als.size(); i++) {
                                                            out.println("<option value=\"" + als.get(i).getId() + "\">" + als.get(i).getDescricao() + "</option>");
                                                        }
                                                    }

                                        %>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center">
                                    <input type="submit">
                                </td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>
            <tr>
                <td align="center"><br/><br/><hr>
                    <%
                                if ((request.getParameter("exibirRelatorio") != null) && request.getParameter("exibirRelatorio").equals("true")) {
                                    Producao pd = new Producao();
                                    if ((request.getParameter("monitorado") != null) && (request.getParameter("monitorado").length() > 0)) {
                                        pd.setColaborador(new Colaborador());
                                        pd.getColaborador().setMatricula(request.getParameter("colaborador"));
                                    }
                                    if ((request.getParameter("processo") != null) && (request.getParameter("processo").length() > 0)) {
                                        pd.setProcesso(new Processo());
                                        pd.getProcesso().setId(Integer.parseInt(request.getParameter("processo")));
                                    }
                                    if ((request.getParameter("data") != null) && (request.getParameter("data").length() > 0)) {
                                        pd.setDtExpediente(ferramentas.DataHora.retornarDataHora(request.getParameter("data"), "dd/MM/yyyy"));
                                    }
                                    if ((request.getParameter("dataFim") != null) && (request.getParameter("dataFim").length() > 0)) {
                                        pd.setDtExpedienteFim(ferramentas.DataHora.retornarDataHora(request.getParameter("dataFim"), "dd/MM/yyyy"));
                                    }
                                    if ((request.getParameter("site") != null) && (request.getParameter("site").length() > 0)) {
                                        pd.setSite(new Site());
                                        pd.getSite().setId(Integer.parseInt(request.getParameter("site")));
                                    }
                                    TipoGrupoInspecao tgi = new TipoGrupoInspecao();
                                    if ((request.getParameter("monitor") != null) && (request.getParameter("monitor").length() > 0)) {
                                        tgi.setColaborador(new Colaborador());
                                        tgi.getColaborador().setMatricula(request.getParameter("monitor"));
                                    }
                                    if ((request.getParameter("grupo") != null) && (request.getParameter("grupo").length() > 0)) {
                                        tgi.setId(Integer.parseInt(request.getParameter("grupo")));
                                    }
                                    tgi.setSite(pd.getSite());
                                    ProducaoGrupoAnalitico pga = new ProducaoGrupoAnalitico();
                                    pga.setProducao(pd);
                                    pga.setTipoGrupoInspecao(tgi);
                                    ArrayList<ProducaoGrupoAnalitico> apga = null;
                                    apga = new ProducaoBO().recuperarProducaoGruposGerencial(pga);
                                    if ((apga != null) && (apga.size() == 0)) {
                                        out.println("<table><tr><td align=\"center\">Nenhum resultado.</td></tr></table>");
                                    } else {
                    %>
                    <br/>
                    <br/>
                    <div class="widget_tableDiv">
                        <table id="myTable" border="1">
                            <thead align="center">
                                <tr>
                                    <td align="center"><b>Grupo</b></td>
                                    <td align="center"><b>Monitor</b></td>
                                    <td align="center"><b>Site</b></td>
                                    <td align="center"><b>Processo</b></td>
                                    <td align="center"><b>Data da Produção</b></td>
                                    <td align="center"><b>Volume</b></td>
                                </tr>
                            </thead>
                            <tbody class="scrollingContent">
                                <%
                                                                        for (int i = 0; i < apga.size(); i++) {
                                                                            out.println("<tr>");
                                                                            out.println("<td align=\"center\">" + apga.get(i).getTipoGrupoInspecao().getId() + " - " + apga.get(i).getTipoGrupoInspecao().getDescricao() + "</td>");
                                                                            out.println("<td align=\"left\">" + apga.get(i).getTipoGrupoInspecao().getColaborador().getMatricula() + " - " + apga.get(i).getTipoGrupoInspecao().getColaborador().getNome() + "</td>");
                                                                            out.println("<td align=\"center\">" + apga.get(i).getProducao().getSite().getDescricao() + "</td>");
                                                                            out.println("<td align=\"center\">" + apga.get(i).getProducao().getProcesso().getDescricao() + "</td>");
                                                                            out.println("<td align=\"center\">" + ferramentas.DataHora.formatarDataHora(apga.get(i).getProducao().getDtExpediente(), ferramentas.DataHora.DATE_FORMAT) + "</td>");
                                                                            out.println("<td align=\"center\"><center>" + apga.get(i).getProducao().getQtdProducao() + "</center></td>");
                                                                            out.println("</tr>");
                                                                        }
                                %>
                            </tbody>
                        </table>
                    </div>
                    <br><br>
                    <script type="text/javascript">
                        initTableWidget('myTable',900,350,Array('S','S','S','S','S','N'));
                    </script>
                    <%
                                    }
                                }
                    %>
                </td>
            </tr>
        </table>
    </body>
</html>